<template>
  <el-dialog
    title="编辑节点属性"
    width="60%"
    :visible.sync="dialogVisible"
    :before-close="closeDialog"
    @open="openDialog">

    <el-form
      :model="form"
      :rules="rules"
      ref="form">
      <el-form-item label="ID" prop="id" :label-width="'120px'">
        <el-input v-model="form.id" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="类型" prop="type" :label-width="'120px'">
        <el-input v-model="form.type" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="名称" prop="nodeName" :label-width="'120px'">
        <el-input v-model="form.text.value"></el-input>
      </el-form-item>
      <el-form-item
        v-if="form.type === 'input' || form.type === 'output'"
        label="连接节点"
        prop="linkNode"
        :label-width="'120px'"
        style="text-align: left;">
        <el-select
          v-model="form.linkNode"
          placeholder="请选择连接节点"
          clearable>
          <el-option
            v-for="node in selectNodeList"
            :key="node.id"
            :label="node.nodeName"
            :value="node.id"
            ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        v-if="form.type === 'switch-node'"
        label="常闭/常开"
        prop="normalState"
        :label-width="'120px'"
        style="text-align: left;">
        <el-switch
          v-model="form.properties.normalState"
          active-color="#13ce66"
          inactive-color="#ff4949">
        </el-switch>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="formDataUpdate">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    props: {
      dialogVisible: {
        type: Boolean,
        required: true
      },
      formData: {
        type: Object,
        required: true
      },
    },
    data: function () {
      return {
        form: {
          text: {
            value: ''
          },
          propreties: {
            normalState: true
          }
        },
        rules: {
          name: [{ required: true, message: '请输入节点名称', trigger: 'blur' }],
          // level: [{ required: true, message: '请选择故障等级', trigger: 'change' }],
        },
      }
    },
    computed: {

    },
    methods: {
      formDataUpdate () {
        this.$refs['form'].validate((valid, errs) => {
          if (valid) {
            this.$emit('data-update', this.form)
            this.closeDialog()
          } else {

          }
        })
      },
      closeDialog () {
        this.$emit('update:dialogVisible', false)
      },
      openDialog () {
        this.form = {...this.formData}
      },
    },
    watch: {

    }
  }
</script>